package com.mxpio.erp.equipment.controller;

import com.mxpio.erp.common.equipment.entity.EquipmentCheckDetailParam;
import com.mxpio.erp.common.equipment.service.EquipmentCheckDetailParamService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

 /**
 * @Description: 点检明细选项
 * @Author: MxpIO
 * @Date:   2021-09-15
 * @Version: V1.0
 */
@Tag(name = "EquipmentCheckDetailParamController", description = "点检明细选项")
@RestController
@RequestMapping("/erp/equipment/spotcheck/tpmCheckDetailParam")
@Slf4j
public class EquipmentCheckDetailParamController {
	@Autowired
	private EquipmentCheckDetailParamService equipmentCheckDetailParamService;

	/**
	 * 分页列表查询
	 *
	 * @param pageNo
	 * @param pageSize
	 * @param criteria
	 * @return
	 */
	@GetMapping(value = "/page")
    @Operation(summary = "点检明细选项-分页列表查询", description = "点检明细选项-分页列表查询", method = "GET")
	public Result<?> queryPageList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   Criteria criteria) {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<EquipmentCheckDetailParam> pageList = equipmentCheckDetailParamService.listPage(EquipmentCheckDetailParam.class,page, criteria);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param equipmentCheckDetailParam
	 * @return
	 */
	@PostMapping(value = "/add")
    @Operation(summary = "点检明细选项-添加", description = "点检明细选项-添加", method = "POST")
	public Result<?> add(@RequestBody EquipmentCheckDetailParam equipmentCheckDetailParam) {
        equipmentCheckDetailParamService.save(equipmentCheckDetailParam);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param equipmentCheckDetailParam
	 * @return
	 */
	@PutMapping(value = "/edit")
    @Operation(summary = "点检明细选项-编辑", description = "点检明细选项-编辑", method = "PUT")
	public Result<?> edit(@RequestBody EquipmentCheckDetailParam equipmentCheckDetailParam) {
        equipmentCheckDetailParamService.update(equipmentCheckDetailParam);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/delete/{id}")
    @Operation(summary = "点检明细选项-通过id删除", description = "点检明细选项-通过id删除", method = "DELETE")
	public Result<?> delete(@PathVariable(name="id",required=true) String id) {
        equipmentCheckDetailParamService.remove(EquipmentCheckDetailParam.class,id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@DeleteMapping(value = "/deleteBatch")
    @Operation(summary = "点检明细选项-批量删除", description = "点检明细选项-批量删除", method = "DELETE")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        Criteria c = Criteria.create().addCriterion("id", Operator.IN, Arrays.asList(ids.split(",")));
        equipmentCheckDetailParamService.removeBatch(EquipmentCheckDetailParam.class,c);
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/{id}")
    @Operation(summary = "点检明细选项-通过id查询", description = "点检明细选项-通过id查询", method = "GET")
	public Result<?> queryById(@PathVariable(name="id",required=true) String id) {
        EquipmentCheckDetailParam equipmentCheckDetailParam = equipmentCheckDetailParamService.getById(EquipmentCheckDetailParam.class,id);
		if(equipmentCheckDetailParam==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(equipmentCheckDetailParam);
	}

//    /**
//    * 导出excel
//    *
//    * @param request
//    * @param equipmentCheckDetailParam
//    */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletRequest request, TpmCheckDetailParam equipmentCheckDetailParam) {
//        return super.exportXls(request, equipmentCheckDetailParam, TpmCheckDetailParam.class, "点检明细选项");
//    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, TpmCheckDetailParam.class);
//    }

}
